package com.yiya.service;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiya.bean.Payment;
import com.yiya.bean.SysUser;
import com.yiya.mapper.PaymentMapper;
import com.yiya.model.PaymentModel;

@Service("paymentService")
public class PaymentService {
	@SuppressWarnings("unused")
	private final static Logger log = Logger.getLogger(PaymentService.class);

	@Autowired
	private PaymentMapper paymentMapper;

	public List<Payment> queryByList(PaymentModel bean) {
		Integer rowCount = queryByCount(bean);
		bean.getPager().setRowCount(rowCount);
		List<Payment> payments = paymentMapper.selectByModel(bean);
		return payments;
	}

	public int queryByCount(PaymentModel bean) {
		return paymentMapper.countByModel(bean);
	}

	public int add(Payment record) {
		return paymentMapper.insert(record);
	}

	public int update(Payment record) {
		return paymentMapper.updateByPrimaryKeySelective(record);
	}

	public Payment queryById(Integer id) {
		return paymentMapper.selectByPrimaryKey(id);
	}

	public void delete(Integer[] ids, SysUser user) {
		for (Integer id : ids) {
			Payment payment = paymentMapper.selectByPrimaryKey(id);
			payment.setDelFlag(1);
			paymentMapper.updateByPrimaryKeySelective(payment);
		}
	}
	
	public void delete(int id, SysUser user) {
			Payment payment = paymentMapper.selectByPrimaryKey(id);
			payment.setDelFlag(1);
			paymentMapper.updateByPrimaryKeySelective(payment);
	}
    /*
	public void importExcel(File file) throws Exception {
		InputStream is = new FileInputStream(file);
		HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
		HSSFSheet sheet = hssfWorkbook.getSheet("Sheet1");
		int rows = sheet.getPhysicalNumberOfRows();
		for (int i = 1; i < rows; i++) {
			HSSFRow row = sheet.getRow(i);
			if (row != null) {
				 Payment payment = new Payment();
				 payment.setPaymentDate(row.getCell(0).getDateCellValue());
				 payment.setCmd(row.getCell(1).getStringCellValue());
				 payment.setStandard(row.getCell(2).getStringCellValue());
				 payment.setQuantity((int)row.getCell(3).getNumericCellValue());
				 payment.setPrice((float)row.getCell(4).getNumericCellValue());
				 payment.setAmount((float)row.getCell(5).getNumericCellValue());
				 payment.setRemark(row.getCell(6).getStringCellValue());
				 paymentMapper.insert(payment);
			}
		}
	}
	*/
}
